package us.mifeng.basicvp.pageui
import android.widget.Toast
import us.mifeng.basicvp.R
import us.mifeng.basicvp.base.BaseActivity
import us.mifeng.basicvp.databinding.ActivityLoginBinding
import us.mifeng.basicvp.model.Login
import us.mifeng.basicvp.viewmodel.LoginViewModel

class LoginActivity : BaseActivity<ActivityLoginBinding,LoginViewModel>() {
    override val layoutId: Int
        get() = R.layout.activity_login

    val mLogin = Login()
    override fun initView() {
        binding.mBtnLogin.setOnClickListener {

           val number =  binding.mEditNumber.text.toString()
           val pass =  binding.mEditPassword.text.toString()
            mLogin.userName = number
            mLogin.password = pass

            if (number.isEmpty() || pass.isEmpty()) {
                Toast(this).setText("请输入账号或密码")
                return@setOnClickListener
            }

            requestLogin()
        }
    }

    fun requestLogin(){
        viewModel.requestLogin (mLogin){ result ->
            if (result != null) {
                Toast(this).setText("登录成功: ${result.token}")
                // 登录成功后的处理逻辑
            } else {
                Toast(this).setText("登录失败，请检查账号或密码")
            }
        }
    }

}